package com.tmeone.erpone.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tmeone.erpone.entity.JsonResult;
import com.tmeone.erpone.entity.TVehicle;
import com.tmeone.erpone.service.ITDriverService;
import com.tmeone.erpone.service.ITVehicleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

@RestController
public class TVehicleController {

    @Autowired
    private ITVehicleService vehicleService;

    @Autowired
    private ITDriverService driverService;

    //分页
    @GetMapping("vehicles")
    public JsonResult pageVehicles(@RequestParam(value = "current",required = false,defaultValue = "1")Integer current,
                                   @RequestParam(value = "pageSize",required = false,defaultValue = "5")Integer pageSize){
        Page<TVehicle> vehiclePage  = new Page<>(current,pageSize);
        return new JsonResult(1,vehicleService.getPageVehicle(vehiclePage));
    }

    /*@PostMapping("vehicle")
    public JsonResult addVehicle(String vehicleName,String logisticsId,String[] driverId,String numberPlate,String vehicleType,
                                 String driverSize,String remarks){
        String vehicleId=UUID.randomUUID().toString().replace("-","").substring(0,8);
        return new JsonResult(1,vehicleService.addVehicle(vehicleId,vehicleName,logisticsId,driverId,numberPlate,vehicleType,driverSize,remarks));
    }*/

    //添加
    @PostMapping("vehicle")
    public JsonResult addVehicle(@RequestBody TVehicle vehicle){
     vehicle.setVehicleId(UUID.randomUUID().toString().replace("-","").substring(0,8));
        return new JsonResult(1,vehicleService.save(vehicle));
    }
    //修改
    @PutMapping("vehicle")
    public JsonResult updateVehicle(@RequestBody TVehicle vehicle){
        return new JsonResult(1,vehicleService.updateById(vehicle));
    }
    //删除
    @DeleteMapping("vehicle/{id}")
    public JsonResult deleteVehicle(@PathVariable String id){
        return new JsonResult(1,vehicleService.removeById(id));
    }

    //查询车辆的分页与证号
    @GetMapping("vehicleNameId")
    public JsonResult vehicleNameId(@RequestParam(value = "current",required = false,defaultValue = "1")Integer current,
                                    @RequestParam(value = "pageSize",required = false,defaultValue = "5")Integer pageSize,String input1,String input2){
        Page<TVehicle> vehiclePage  = new Page<>(1,pageSize);
        return new JsonResult(1,vehicleService.pageVehicleNameId(vehiclePage,input1,input2));
    }

    //查询所有驾驶员
    @GetMapping("driverAll")
    public JsonResult selectVehicleAll(){
        return new JsonResult(1,driverService.list());
    }

}
